package com.bwie.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.mapper.CategoryMapper;
import com.bwie.pojo.Category;
import com.bwie.service.CategoryService;
import com.bwie.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @program: day0423-pxx
 * @ClassName CategoryServiceImpl
 * @description:
 * @author: 段阳
 * @create: 2024-04-23 10:52
 **/
@Service
@Transactional
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;
    @Override
    public R addNewType(Category category) {
        categoryMapper.insert(category);
        Long id = category.getId();
        Category category1 = categoryMapper.selectById(id);
        return R.success("success",category1);
    }

    @Override
    public List<String> queryNamesByIds(List<Long> ids) {

        ArrayList<String> list = new ArrayList<>();
        ids.forEach(id -> {
            Category category = categoryMapper.selectById(id);
            list.add(category.getName());
        });

        return list;
    }
}